<%--
 * edit.jsp
 *
 * Copyright (C) 2013 Universidad de Sevilla
 * 
 * The use of this project is hereby constrained to the conditions of the 
 * TDG Licence, a copy of which you may download from 
 * http://www.tdg-seville.info/License.html
 --%>

<%@page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>

<%@taglib prefix="jstl" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
<%@taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@taglib prefix="security"
	uri="http://www.springframework.org/security/tags"%>
<%@taglib prefix="display" uri="http://displaytag.sf.net"%>
<%@taglib prefix="acme" tagdir="/WEB-INF/tags"%>


<form:form action="${requestURI}" modelAttribute="itemForm">

	<form:hidden path="itemId" />
	<form:hidden path="seller" />


	<acme:textbox code="availableItem.referenceNumber"
		path="referenceNumber" readonly="true" />

	<jstl:if test="${!isNew && !isSeller }">

		<acme:textbox code="availableItem.name" path="name" readonly="true" />
		<acme:textarea code="availableItem.description" path="description"
			readonly="true" />
		<spring:message code="availableItem.price" />
		<acme:textbox code="availableItem.amount" path="amount"
			readonly="true" />
		<acme:textbox code="availableItem.currency" path="currency"
			readonly="true" />
		<acme:textbox code="availableItem.units" path="availableUnits"
			readonly="true" />

		<acme:textbox code="availableItem.state" path="state" readonly="true" />

		<br />
		<acme:textbox code="availableItem.seller" path="seller.name"
			readonly="true" />

	</jstl:if>

	<jstl:if test="${isNew || isSeller}">
		<acme:textbox code="availableItem.name" path="name" />
		<acme:textarea code="availableItem.description" path="description" />
		<spring:message code="availableItem.price" />
		<acme:textbox code="availableItem.amount" path="amount" />
		<acme:textbox code="availableItem.currency" path="currency" />
		<acme:textbox code="availableItem.units" path="availableUnits" />
		<form:label path="state">
			<spring:message code="availableItem.state" />
		</form:label>
		<spring:message code="availableItem.state.0" var="New" />
		<spring:message code="availableItem.state.1" var="used" />
		<form:select path="state">
			<form:option value="new" label="${New}" />
			<form:option value="used" label="${used}" />
		</form:select>
		<br />
		<acme:textbox code="availableItem.seller" path="seller.name"
			readonly="true" />

	</jstl:if>

	<jstl:if test="${isNew}">
		<acme:submit code="availableItem.create" name="save" />
	</jstl:if>

	<jstl:if test="${isSeller}">

		<acme:submit code="availableItem.update" name="save" />
	</jstl:if>

	<jstl:if test="${isSeller && !hasOrder}">

		<input type="submit" name="delete"
			value="<spring:message code="availableItem.delete" />"
			onclick="return confirm('<spring:message code = "availableItem.confirm.delete"/>')" />

	</jstl:if>
	<!-- Shopping Cart buttons -->
	<jstl:if test="${!isSeller && !isNew && available && !inCart}">
		<acme:cancel code="availableItem.addCart"
			url="/availableItem/customer/addToCart.do?availableItemId=${itemId}" />
	</jstl:if>
	<jstl:if test="${!isSeller && !isNew && inCart}">
		<jstl:if test="${available && !max}">
			<acme:cancel code="availableItem.addAnotherCart"
				url="/availableItem/customer/addAnotherToCart.do?availableItemId=${itemId}" />
		</jstl:if>
		<acme:cancel code="availableItem.removeCart"
			url="/availableItem/customer/removeFromCart.do?availableItemId=${itemId}" />
	</jstl:if>

	<!-- Wish list buttons -->
	<jstl:if test="${!isSeller && !isNew && !wished}">
		<acme:cancel code="availableItem.addWish"
			url="/availableItem/customer/addToWishlist.do?availableItemId=${itemId}" />
	</jstl:if>
	<jstl:if test="${!isSeller && !isNew && wished}">
		<acme:cancel code="availableItem.removeWish"
			url="/availableItem/customer/removeFromWishlist.do?availableItemId=${itemId}" />
	</jstl:if>
	<!-- --- -->
	<jstl:if test="${!isNew }">
		<h1>
			<spring:message code="availableItem.comments" />
		</h1>
		<display:table pagesize="5" class="displaytag" keepStatus="true"
			name="comments" requestURI="${requestURI}" id="row">

			<spring:message code="comment.creationMoment"
				var="commentCreationMomentHeader" />
			<display:column property="creationMoment"
				title="${commentCreationMomentHeader}" sortable="true"
				format="{0,date,dd/MM/yyyy HH:mm}" />

			<spring:message code="comment.text" var="commentTextHeader" />
			<display:column property="text" title="${commentTextHeader}"
				sortable="false" />

			<spring:message code="comment.rating" var="commentRatingHeader" />
			<display:column property="rating" title="${commentRatingHeader}"
				sortable="true" />
		</display:table>
	</jstl:if>
	<jstl:if test="${isBuyer}">
		<acme:cancel code="availableItem.createComment"
			url="/comment/customer/create.do?availableItemId=${itemId}" />
	</jstl:if>
	<acme:cancel code="availableItem.cancel" url="${backURI}" />

</form:form>